package com.dm.mcode.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.TextView;

import com.dm.mcode.R;
import com.dm.mcode.util.Colors;
import com.dm.mcode.util.HandlerTip;
import com.dm.mcode.util.StatusBarUtil;
import com.github.ybq.android.spinkit.SpinKitView;
import com.github.ybq.android.spinkit.SpriteFactory;
import com.github.ybq.android.spinkit.sprite.Sprite;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.github.ybq.android.spinkit.Style.CHASING_DOTS;

public class SplashActivity extends BaseActivity {

    int milliseconds = 3000;
    @Bind(R.id.spin_kit)
    SpinKitView spinKit;
    @Bind(R.id.name)
    TextView name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spalsh);
        ButterKnife.bind(this);

        //设置状态栏透明
        StatusBarUtil.setTranslucentBackground(this);
        name.setText("天下无码");
        Sprite drawable = SpriteFactory.create(CHASING_DOTS);
        spinKit.setIndeterminateDrawable(drawable);
        //文字动画效果
        ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1.3f, 1f, 1.3f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(2000);
        scaleAnimation.setFillAfter(true);
        name.startAnimation(scaleAnimation);

        HandlerTip.getInstance().postDelayed(milliseconds, new HandlerTip.HandlerCallback() {
            @Override
            public void postDelayed() {
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
                finish();
            }

        });
        int colorIndex = (int) (Math.random() * Colors.colors.length);
        getWindow().getDecorView().setBackgroundColor(Colors.colors[colorIndex]);
    }

    @OnClick({R.id.spin_kit, R.id.name})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.spin_kit:
                break;
            case R.id.name:
                break;
        }
    }
}
